<?php

/**
 * @author Rizky Tahara Shita
 * @website http://tahara.web.id
 * @email rizky.tahara@gmail.com
 * @copyright b'IT Cyber Solution
 */
require_once(APPPATH.'controllers/admin/applications.php');
class Holiday extends Applications
{
	public function __construct()
	{
		parent::__construct();

		/**
		 * @description check the session variables
		 */
		$this->M_login->session_check();

		/**
		 * @description the URL
		 */
		$this->bz_segment['END'] = 5;
		$this->bz_segment['URL'] = $this->M_functions->segment_create();
		$this->bz_segment['SITE_URL'] = site_url($this->bz_segment['URL']);

		/**
		 * @description access rights
		 */
		$this->access_rights = $this->M_menu->valid_check('db_default', $this->session->userdata('session_user_id'));
		$this->access_rights = array
			(
				'ADD' => in_array('add', $this->access_rights) ? TRUE : FALSE
				, 'EDIT' => in_array('edit', $this->access_rights) ? TRUE : FALSE
				, 'DELETE' => in_array('delete', $this->access_rights) ? TRUE : FALSE
			);

		/**
		 * @description initialize variables for database
		 */
		$this->tbl_attr = array
			(
				'TABLE' => array
					(
						'NAME' => 'hris_attendance_holiday'
						, 'NAME_ALIAS' => 'hris_attendance_holiday a'
						, 'PRIMARY' => array
							(
								'SHOW' => FALSE
								, 'DATA' => array('id')
							)
					)
				, 'TABLE_HOLIDAY_COMPANY' => array
					(
						'NAME' => 'hris_attendance_holiday_company'
						, 'NAME_ALIAS' => 'hris_attendance_holiday_company a'
						, 'PRIMARY' => array
							(
								'SHOW' => FALSE
								, 'DATA' => array('holiday__id', 'company__id')
							)
					)
				, 'TABLE_HOLIDAY_COMPANY_WORK_LOCATION' => array
					(
						'NAME' => 'hris_attendance_holiday_company_work_location'
						, 'NAME_ALIAS' => 'hris_attendance_holiday_company_work_location a'
						, 'PRIMARY' => array
							(
								'SHOW' => FALSE
								, 'DATA' => array('holiday__id', 'company__id', 'work_location__id')
							)
					)
				, 'VIEW' => array
					(
						'HEADING' => array
							(
								$this->lang->line('hris_name')
								, $this->lang->line('hris_start')
								, $this->lang->line('hris_end')
								, $this->access_rights['DELETE'] ? '&nbsp;' : NULL
							)
						, 'FIELDS' => 'id, name, date_start, date_end'
						, 'FIELDS_EDIT' => 'name'
						, 'FIELDS_ORDER' => 'year(date_start), month(date_start)'
						, 'TOT_ROW' => $this->web_data['BISKITZ']['SETTINGS']['BISKITZ_VIEW_TOT_ROW']
						, 'TABLE' => array
							(
								'WHERE' => array()
							)
					)
				, 'FORM' => array
					(
						'FIELDS' => 'id, name, date_start, date_end'
						, 'FIELDS_ORDER' => ''
						, 'COLUMN' => 4
						, 'COLUMN_JOIN' => 2
					)
				, 'URL' => array
					(
						'FORM' => $this->bz_segment['SITE_URL'].'/form'
						, 'VIEW' => $this->bz_segment['SITE_URL'].'/view'
					)
			);

		/**
		 * @description template lite variables
		 */
		$this->bz_tlite_var['CACHE_PATH'] = $this->bz_tlite_var['SESSION']['USER_ID'].'|'.str_replace('/', '|', $this->bz_segment['URL']);
		$this->bz_tlite_var['CACHE'] = array
			(
				'PUBLIC' => $this->bz_tlite_var['SESSION']['USER_ID']
				, 'PRIVATE' => array
					(
						'GLOBAL' => $this->bz_tlite_var['CACHE_PATH']
						, 'VIEW' => $this->bz_tlite_var['CACHE_PATH'].'|view'
						, 'FORM' => $this->bz_tlite_var['CACHE_PATH'].'|form'
					)
			);
	}


	/**
	 * @function index()
	 * @description main controller
	 */
	public function index()
	{
		/**
		 * @description choose which controller to show
		 */
		redirect($this->tbl_attr['URL']['VIEW']);
	}


	/**
	 * @function view()
	 * @description view table list of data
	 */
	public function view($prm_page = '', $prm_search_term = '')
	{
		if ($this->web_data['BISKITZ']['HEADER']['BROWSER_SUPPORTED'] == '')
		{
			/**
			 * @description load the models
			 */
			$this->load->model('M_viewlist');
			$this->load->library('encrypt');


			/**
			 * @description process the searching
			 */
			if (trim($this->input->post('txt_search')) != '')
			{
				$search_string = $this->encrypt->encode($this->input->post('txt_search'));
				redirect($this->bz_segment['SITE_URL'].'/view/0/'.$search_string);
			}
			if (trim($prm_search_term) != '')
			{
				$prm_search_term = strtolower($this->encrypt->decode($prm_search_term));
				$search_term = array
					(
						'lower(name)' => $prm_search_term
						, 'date_start' => $prm_search_term
						, 'date_end' => $prm_search_term
					);
			}
			else
			{
				$search_term = '';
			}


			/**
			 * @description if there isn't any css/ajax cache, build it! else show cache!
			 */
			if ( ! $this->bz_tlite->is_cached($this->bz_tlite_var['NAMES']['CSS'], $this->bz_tlite_var['CACHE']['PRIVATE']['VIEW']))
			{
				/**
				 * @section begin page init
				 */
					/**
					 * @description show the menu
					 */
					$menu = $this->M_menu->shows();
					$this->web_data['JAVASCRIPT_MENU'] = $menu['JAVASCRIPT_MENU'];
					$this->web_data['PAGE']['MENU'] = $menu['PAGE']['MENU'];

					/**
					 * @description init the css and the ajax needed
					 */
					$css_files = array
						(
							array('layout' => 'screen')
							, array('tipsy/tipsy' => 'screen')
							, array('form_icon_bar' => 'screen')
							, array('nanoscroller/nanoscroller' => ($menu['PAGE']['MENU']['FAVORITE']['LIST'] != 'Error') ? 'screen' : NULL)
							, array('shortcut_bar' => ($menu['PAGE']['MENU']['FAVORITE']['LIST'] != 'Error') ? 'screen' : NULL)
							, array('ddm/multi-ddm' => 'screen')
						);
					$js_files = array
						(
							'js/plugins/ddm' => array('jquery.multi-ddm.pack')
							, 'js/plugins/nanoscroller' => ($menu['PAGE']['MENU']['FAVORITE']['LIST'] != 'Error') ? array('jquery.nanoscroller.min', 'overthrow.min') : NULL
							, 'js/plugins/tipsy' => array('jquery.tipsy.pack')
							, $this->web_data['BISKITZ']['SETTINGS']['BISKITZ_JS_FUNCTIONS_PATH'] => array('common', 'form', 'error')
							, 'themes/'.$this->web_data['BISKITZ']['SETTINGS']['BISKITZ_THEME_ADMIN'].'/'.$this->web_data['BISKITZ']['SETTINGS']['BISKITZ_JS_PATH'] => array('common')
						);
				/**
				 * @section end page init
				 */


				/**
				 * @section begin generate template variables
				 */
					/**
					 * @description css and ajax
					 */
					$this->web_data['PAGE']['CSS_FILES'] = $this->M_template->css_generate($css_files, $this->web_data['BISKITZ']['SETTINGS']['BISKITZ_THEME_ADMIN']);
					$this->web_data['PAGE']['JAVASCRIPT_FILES'] = $this->M_template->js_generate($js_files);

					/**
					 * @description initialize the additional javascript
					 */
					if ($menu['PAGE']['MENU']['FAVORITE']['LIST'] != 'Error')
					{
						$this->web_data['JAVASCRIPT'] .= '
							<script>
								$(function()
								{
									$(".nano").nanoScroller({preventPageScrolling: true});
								});
							</script>
							';
					}

					/**
					 * @description menu descriptions
					 */
					$this->web_data['PAGE']['DETAIL'] = $this->M_menu->detail();
				/**
				 * @section end generate template variables
				 */
			}


			/**
			 * @section begin table view init
			 */
				/**
				 * @description init the pagination
				 */
				$paging_init = array
					(
						'base_url' => $this->tbl_attr['URL']['VIEW']
						, 'total_rows' => $this->M_database->total_rows
							(
								'db_default'
								, $this->tbl_attr['TABLE']['NAME']
								, $this->tbl_attr['VIEW']['TABLE']['WHERE']
								, FALSE
								, $search_term
							)
						, 'per_page' => $this->tbl_attr['VIEW']['TOT_ROW']
						, 'uri_segment' => $this->bz_segment['END'] + 2
					);

				$this->load->library(array('pagination'));
				$this->pagination->initialize($paging_init);
				$paging_link = $this->pagination->my_paging_links(TRUE, $this->bz_segment['END'] + 3);

				/**
				 * @description init the command button
				 */
				$this->load->model('admin/M_command_bar');
				$view_list_commands = $this->M_command_bar->view($prm_search_term, $paging_link);

				/**
				 * @description init the table list
				 */
				$view_list_content = $this->M_viewlist->generate
					(
						'db_default'
						, $this->tbl_attr['VIEW']['FIELDS'], $this->tbl_attr['TABLE']['PRIMARY'], $this->tbl_attr['VIEW']['FIELDS_EDIT'], $this->tbl_attr['VIEW']['FIELDS_ORDER']
						, $this->tbl_attr['TABLE']['NAME_ALIAS'], $this->tbl_attr['VIEW']['TABLE']['WHERE']
						, $search_term
						, $this->bz_segment['URL']
						, $this->tbl_attr['VIEW']['TOT_ROW']
						, 'form'
						, $this->access_rights['EDIT']
						, $this->access_rights['DELETE']
					);

				if (is_array($view_list_content))
				{
					$this->table->set_heading($this->tbl_attr['VIEW']['HEADING']);
					$view_list_content = $this->table->generate($view_list_content);
				}
				else
				{
					$view_list_content = '<center class="error_field">'.$this->lang->line('data_view_error').'</center>';
				}
			/**
			 * @section end table view init
			 */


			/**
			 * @section begin generate template variables
			 */

				/**
				 * @description view list
				 */
				$this->web_data['PAGE']['VIEW'] = array
					(
						'FORM' => array
							(
								'OPEN' => form_open($this->tbl_attr['URL']['VIEW'], array('id' => 'frm_header', 'onSubmit' => 'return false'), '')
							)
						, 'COMMANDS' => $view_list_commands
						, 'LISTS' => $view_list_content
					);
			/**
			 * @section end generate template variables
			 */


			/**
			 * @description log the action!
			 */
			$this->M_log->write
				(
					'db_default'
					, trim($prm_page) != ''
						? sprintf
							(
								trim($prm_search_term) != '' ? $this->lang->line('log_view_search') : $this->lang->line('log_view_page')
								, $this->router->class
								, $this->pagination->cur_page
								, $prm_search_term
							)
						: sprintf($this->lang->line('log_view_access'), $this->router->class)
				);



		}
		else
		{
			/**
			 * @section Browser NOT Supported
			 */
				/**
				 * @description browser not supported message error
				 */
				$css_files = array(array('layout' => 'screen'));


				/**
				 * @section begin generate template variables
				 */
					/**
					 * @description css and ajax
					 */
					$this->web_data['PAGE']['CSS_FILES'] = $this->M_template->css_generate($css_files, $this->web_data['BISKITZ']['SETTINGS']['BISKITZ_THEME_ADMIN']);
				/**
				 * @section end generate template variables
				 */

		}



		/**
		 * @description output template variables
		 */
		$this->bz_tlite->assign('WEB_DATA', $this->web_data);


		/**
		 * @section begin output
		 */
		$this->bz_tlite->display($this->bz_tlite_var['NAMES']['HEADER'], $this->bz_tlite_var['CACHE']['PUBLIC']);
		$this->bz_tlite->display($this->bz_tlite_var['NAMES']['CSS'], $this->bz_tlite_var['CACHE']['PRIVATE']['VIEW']);
		$this->bz_tlite->display($this->bz_tlite_var['NAMES']['MENU'], $this->bz_tlite_var['CACHE']['PUBLIC']);
		$this->bz_tlite->display($this->bz_tlite_var['NAMES']['CONTENT_DESCRIPTION'], $this->bz_tlite_var['CACHE']['PRIVATE']['GLOBAL']);

		$this->bz_tlite->cache = FALSE;
		$this->bz_tlite->display($this->bz_tlite_var['NAMES']['CONTENT_FORM_COMMAND_BAR']);
		$this->bz_tlite->display($this->bz_tlite_var['NAMES']['CONTENT_FORM']);

		$this->bz_tlite->cache = TRUE;
		$this->bz_tlite->display($this->bz_tlite_var['NAMES']['CONTENT_SHORTCUT_BAR'], $this->bz_tlite_var['CACHE']['PUBLIC']);
		$this->bz_tlite->display($this->bz_tlite_var['NAMES']['FOOTER'], $this->bz_tlite_var['CACHE']['PUBLIC']);
		$this->bz_tlite->display($this->bz_tlite_var['NAMES']['JAVASCRIPT'], $this->bz_tlite_var['CACHE']['PRIVATE']['VIEW']);
		$this->bz_tlite->display($this->bz_tlite_var['NAMES']['FOOTER_END'], $this->bz_tlite_var['CACHE']['PUBLIC']);
		/**
		 * @section end output
		 */
	}


	/**
	 * @function form()
	 * @description form for data entry
	 */
	public function form($prm_key = '')
	{
		if ($this->web_data['BISKITZ']['HEADER']['BROWSER_SUPPORTED'] == '')
		{
			/**
			 * @description if the user has ADD or EDIT access, show the form!
			 */
			if ($this->access_rights['ADD'] OR ($this->access_rights['EDIT'] && trim($prm_key) != ''))
			{
				/**
				 * @description if there isn't any css/ajax cache, build it! else show cache!
				 */
				if ( ! $this->bz_tlite->is_cached($this->bz_tlite_var['NAMES']['CSS'], $this->bz_tlite_var['CACHE']['PRIVATE']['FORM']))
				{
					/**
					 * @section begin page init
					 */
						/**
						 * @description show the menu
						 */
						$menu = $this->M_menu->shows();
						$this->web_data['JAVASCRIPT_MENU'] = $menu['JAVASCRIPT_MENU'];
						$this->web_data['PAGE']['MENU'] = $menu['PAGE']['MENU'];

						/**
						 * @description init the css and the ajax needed
						 */
						$css_files = array
							(
								array('layout' => 'screen')
								, array('tipsy/tipsy' => 'screen')
								, array('validate/validate' => 'screen')
								, array('form_icon_bar' => 'screen')
								, array('nanoscroller/nanoscroller' => ($menu['PAGE']['MENU']['FAVORITE']['LIST'] != 'Error') ? 'screen' : NULL)
								, array('shortcut_bar' => ($menu['PAGE']['MENU']['FAVORITE']['LIST'] != 'Error') ? 'screen' : NULL)
								, array('dynDateTime/dynDateTime' => 'screen')
								, array('ddm/multi-ddm' => 'screen')
							);
						$js_files = array
							(
								'js/plugins/ddm' => array('jquery.multi-ddm.pack')
								, 'js/plugins/nanoscroller' => ($menu['PAGE']['MENU']['FAVORITE']['LIST'] != 'Error') ? array('jquery.nanoscroller.min', 'overthrow.min') : NULL
								, 'js/plugins/validate' => array('jquery.validate.pack', 'jquery.metadata')
								, 'js/plugins/tipsy' => array('jquery.tipsy.pack')
								, 'js/plugins/dynDateTime' => array('jquery.dynDateTime.pack')
								, 'js/plugins/dynDateTime/lang/pack' => array('calendar-'.$this->session->userdata('session_user_language_abbr'))
								, $this->web_data['BISKITZ']['SETTINGS']['BISKITZ_JS_FUNCTIONS_PATH'] => array('common', 'form', 'error', 'datetime_picker')
								, 'themes/'.$this->web_data['BISKITZ']['SETTINGS']['BISKITZ_THEME_ADMIN'].'/'.$this->web_data['BISKITZ']['SETTINGS']['BISKITZ_JS_PATH'] => array('common')
							);
					/**
					 * @section end page init
					 */


					/**
					 * @section begin form initialize
					 */
						/**
						 * @description load the models
						 */
						$this->load->model('admin/hris/HRIS_M_live_data');


						/**
						 * @description initialize the form elements
						 */
						$form_content_join[] = array
							(
								'<b>'.$this->lang->line('hris_name').'</b><br /><small>'.$this->lang->line('fields_required').'</small>'
								, array
									(
										'data' => form_input
											(
												array
												(
													'type' => 'hidden'
													, 'name' => 'txtinput[0]', 'id' => 'txt0'
													, 'size' => '18', 'maxlength' => '18'
													, 'readOnly' => 'readOnly', 'class' => 'read_only'
												)
											)
											. form_input
												(
													array
													(
														'name' => 'txtinput[1]', 'id' => 'txt1'
														, 'size' => '50', 'maxlength' => '50'
														, 'class' => '{validate: {required: true}}'
														, 'shortcut_f2' => $this->tbl_attr['URL']['VIEW']
													)
												)
										, 'colspan' => 3
									)
							);

						$form_content[] = array
							(
								'<b>'.$this->lang->line('hris_start').'</b>'
								, form_input
									(
										array
										(
											'name' => 'txtinput[2]', 'id' => 'txt2'
											, 'size' => '11', 'maxlength' => '10'
											, 'readOnly' => 'readOnly', 'class' => '{validate: {required: true}} input_calendar do_not_change'
											, 'shortcut_f2' => $this->tbl_attr['URL']['VIEW']
										)
										, date('Y-m-d')
										, 'onBlur="javascript: calendar.hide();"'
									)

								, '<b>'.$this->lang->line('hris_end').'</b>'
								, form_input
									(
										array
										(
											'name' => 'txtinput[3]', 'id' => 'txt3'
											, 'size' => '11', 'maxlength' => '10'
											, 'readOnly' => 'readOnly', 'class' => '{validate: {required: true}} input_calendar do_not_change'
											, 'shortcut_f2' => $this->tbl_attr['URL']['VIEW']
										)
										, date('Y-m-d')
										, 'onBlur="javascript: calendar.hide();"'
									)
							);

						$form_content_join[] = array
							(
								array('data' => '<b>'.$this->lang->line('hris_company_name').'</b><br /><small>'.$this->lang->line('fields_choose_more').'</small>', 'valign' => 'top')
								, array
									(
										'data' => form_dropdown
											(
												'txtinput[4][]'
												, $this->HRIS_M_live_data->combo_fill('db_default', 'company_profile', '', 'RECURSIVE', array(), FALSE, '', FALSE)
												, ''
												, 'id="txt4" class="{validate: {required: true}}"'
													. ' multiple="multiple" size="5" style="width: 100%"'
											)
											. '<div align="right">'.anchor('#', $this->lang->line('hris_select_toggle'), array('class' => 'link_select_toggle')).'</div>'
										, 'colspan' => 3
									)

								, array('data' => '<b>'.$this->lang->line('hris_work_location').'</b><br /><small>'.$this->lang->line('fields_choose_more').'</small>', 'valign' => 'top')
								, array
									(
										'data' => form_dropdown
											(
												'txtinput[5][]'
												, $this->HRIS_M_live_data->combo_fill('db_default', 'company_work_location', '', 'RECURSIVE', array(), FALSE, '', FALSE)
												, ''
												, 'id="txt5" class="{validate: {required: true}} latest_object"'
													. ' multiple="multiple" size="15" style="width: 100%"'
													. ' shortcut_enter="$(\'#btn_save\').click();"'
											)
											. '<div align="right">'.anchor('#', $this->lang->line('hris_select_toggle'), array('class' => 'link_select_toggle')).'</div>'


										. (
												$this->access_rights['ADD']
												? form_button
													(
														array('id' => 'btn_add_detail', 'class' => 'input_default hidden')
														, $this->lang->line('button_add_detail')
													)
												: NULL
											)
										. form_submit
											(
												array('id' => 'btn_save', 'class' => 'input_not_default hidden')
												, $this->lang->line('button_save')
											)
										, 'colspan' => 3
									)
							);
						/**
						 * @description create the form and elements
						 */
						$this->table->clear();

						$form[] = $this->table->make_columns($form_content_join[0], $this->tbl_attr['FORM']['COLUMN_JOIN']);
						$form[] = $this->table->make_columns($form_content[0], $this->tbl_attr['FORM']['COLUMN']);
						$form[] = $this->table->make_columns($form_content_join[1], $this->tbl_attr['FORM']['COLUMN_JOIN']);

						$form_content = $this->table->generate(array_merge($form[0], $form[1], $form[2]));
					/**
					 * @section end form initialize
					 */



					/**
					 * @section begin generate template variables
					 */
						/**
						 * @description css and ajax
						 */
						$this->web_data['PAGE']['CSS_FILES'] = $this->M_template->css_generate($css_files, $this->web_data['BISKITZ']['SETTINGS']['BISKITZ_THEME_ADMIN']);
						$this->web_data['PAGE']['JAVASCRIPT_FILES'] = $this->M_template->js_generate($js_files);

						/**
						 * @description initialize the additional javascript
						 */
						$this->web_data['JAVASCRIPT'] .= '
							<script>
								$(function()
								{
									var select_toggle4 = true;
									var select_toggle5 = true;

									$("#btn_save").click
										(function()
										{
											js_form_action_validate
											(
												"'.$this->bz_segment['SITE_URL'].'", "ajx_", "insert", ""
												, "#frm_header", "#process", "#error_message"
												, "validate"
											);
										});


									$("#txt4").change
										(function()
										{
											select_toggle5 = true;
											$("#txt5").empty().append( $("<option></option>").val("") );

											if ($(this).val() != "")
											{
												js_form_action
												(
													"'.$this->bz_segment['SITE_URL'].'", "ajx_live_work_location_", "combo_put", encodeURIComponent($(this).val()) + "/5"
													, "#frm_header", "#process", "#error_message"
												);
											}
										});


									js_datetime_picker_show("txt2", "txt3");
									js_datetime_picker_show("txt3", "btn_add_detail");

									$(".link_select_toggle").click
										(function()
										{
											select_id = $(this).parent().prev().attr("id");
											$("#" + select_id + " option").prop("selected", (select_id == "txt4") ? select_toggle4 : select_toggle5);
											if (select_id == "txt4")
											{
												select_toggle4 = ! select_toggle4;
												$("#" + select_id).change();
											}
											else
											{
												select_toggle5 = ! select_toggle5;
											}
											return false;
										});

									$("#txt1").focus().select();
						';

						if ($menu['PAGE']['MENU']['FAVORITE']['LIST'] != 'Error')
						{
							$this->web_data['JAVASCRIPT'] .= '$(".nano").nanoScroller({preventPageScrolling: true});';
						}

						$this->web_data['JAVASCRIPT'] .= '
								});
							</script>
						';

						/**
						 * @description menu descriptions
						 */
						$this->web_data['PAGE']['DETAIL'] = $this->M_menu->detail();

						/**
						 * @description icon bar
						 */
						$this->load->model('admin/M_command_bar');
						$this->web_data['PAGE']['ICON_BAR'] = $this->M_command_bar->form();

						/**
						 * @description form dialogs
						 */
						$this->web_data['PAGE']['FORM'] = array
							(
								'OPEN' => form_open('', array('id' => 'frm_header', 'onSubmit' => 'return false'), '')
								, 'CONTENT' => $form_content
							);

						/**
						 * @description notes
						 */
						$this->web_data['PAGE']['NOTES'] = array
							(
								'USE' => 'TRUE'
								, 'MESSAGE' => array
									(
										'SHORTCUTS' => $this->lang->line('notes_shortcuts')
										, 'ADDITIONAL' => $this->lang->line('notes_additional')
									)
							);
					/**
					 * @section end generate template variables
					 */
				}


				/**
				 * @description get the data for editing via ajax
				 */
				if ($this->access_rights['EDIT'] && trim($prm_key) != '')
				{
					$this->web_data['JAVASCRIPT_EXTEND'] = '
						<script>
							$(function()
							{
								js_form_action
								(
									"'.$this->bz_segment['SITE_URL'].'", "ajx_data_", "put", "'.$prm_key.'"
									, "#frm_header", "#process", "#error_message"
								);
							});
						</script>
					';
				}


				/**
				 * @description log the action!
				 */
				$this->M_log->write('db_default', sprintf($this->lang->line('log_form_access'), $this->router->class, 'form'));
			}
			else
			{
				/**
				 * @description doesn't have ADD or EDIT access? redirect to desktop
				 */
				redirect('admin/desktop');
			}



		}
		else
		{
			/**
			 * @section Browser NOT Supported
			 */
				/**
				 * @description browser not supported message error
				 */
				$css_files = array(array('layout' => 'screen'));


				/**
				 * @section begin generate template variables
				 */
					/**
					 * @description css and ajax
					 */
					$this->web_data['PAGE']['CSS_FILES'] = $this->M_template->css_generate($css_files, $this->web_data['BISKITZ']['SETTINGS']['BISKITZ_THEME_ADMIN']);
				/**
				 * @section end generate template variables
				 */
		}



		/**
		 * @description output template variables
		 */
		$this->bz_tlite->assign('WEB_DATA', $this->web_data);


		/**
		 * @section begin output
		 */
		$this->bz_tlite->display($this->bz_tlite_var['NAMES']['HEADER'], $this->bz_tlite_var['CACHE']['PUBLIC']);
		$this->bz_tlite->display($this->bz_tlite_var['NAMES']['CSS'], $this->bz_tlite_var['CACHE']['PRIVATE']['FORM']);
		$this->bz_tlite->display($this->bz_tlite_var['NAMES']['MENU'], $this->bz_tlite_var['CACHE']['PUBLIC']);
		$this->bz_tlite->display($this->bz_tlite_var['NAMES']['CONTENT_DESCRIPTION'], $this->bz_tlite_var['CACHE']['PRIVATE']['GLOBAL']);
		$this->bz_tlite->display($this->bz_tlite_var['NAMES']['CONTENT_FORM_ICON_BAR'], $this->bz_tlite_var['CACHE']['PRIVATE']['FORM']);
		$this->bz_tlite->display($this->bz_tlite_var['NAMES']['CONTENT_FORM'], $this->bz_tlite_var['CACHE']['PRIVATE']['FORM']);
		$this->bz_tlite->display($this->bz_tlite_var['NAMES']['CONTENT_SHORTCUT_BAR'], $this->bz_tlite_var['CACHE']['PUBLIC']);
		$this->bz_tlite->display($this->bz_tlite_var['NAMES']['FOOTER'], $this->bz_tlite_var['CACHE']['PUBLIC']);
		$this->bz_tlite->display($this->bz_tlite_var['NAMES']['JAVASCRIPT'], $this->bz_tlite_var['CACHE']['PRIVATE']['FORM']);

		$this->bz_tlite->cache = FALSE;
		$this->bz_tlite->display($this->bz_tlite_var['NAMES']['JAVASCRIPT_EXTEND']);

		$this->bz_tlite->cache = TRUE;
		$this->bz_tlite->display($this->bz_tlite_var['NAMES']['FOOTER_END'], $this->bz_tlite_var['CACHE']['PUBLIC']);
		/**
		 * @section end output
		 */
	}



/**
 * @section AJAX Action Section
 */

	/**
	 * @function ajx_insert()
	 * @description insert the data
	 */
	public function ajx_insert()
	{
		if ($this->input->is_ajax_request() && ($this->access_rights['ADD'] OR $this->access_rights['EDIT']))
		{
			/**
			 * @description load the models
			 */
			$this->load->model(array('admin/M_live_data', 'admin/hris/HRIS_M_live_data'));


			$return_value = $this->M_live_data->insert
				(
					'db_default'
					, $this->tbl_attr['TABLE']['NAME']
					, array('id' => $this->input->post('txtinput[0]'))
					, $this->input->post('txtinput')
				);

			if ($return_value[0] == 'js_action_update')
			{
				$return_value = array_merge($return_value, array($this->access_rights));
			}
			else
			{
				/**
				 * @description process the company & work location detail
				 */
				if (trim($this->input->post('txtinput[0]')) == '')
				{
					$header['ID'] = $this->M_database->max_id('db_default', $this->tbl_attr['TABLE']['NAME'], 'id');
				}
				else
				{
					$header['ID'] = $this->input->post('txtinput[0]');
				}


				/**
				 * @description process the company
				 */
				$data = array();
				foreach ($this->input->post('txtinput[4]') as $company_id)
				{
					$data[] = array('holiday__id' => $header['ID'], 'company__id' => $company_id);
				}

				$this->HRIS_M_live_data->combo_data_set
					(
						'db_default'
						, array
							(
								'NAME' => $this->tbl_attr['TABLE_HOLIDAY_COMPANY']['NAME']
								, 'WHERE' => array('holiday__id' => $header['ID'])
							)
						, $data
					);


				/**
				 * @description process the work location
				 */
				$data = array();
				foreach ($this->input->post('txtinput[5]') as $work_location_id)
				{
					$get_company_id = $this->M_database->datas
						(
							'db_default'
							, 'hris_organization_company_work_location'
							, array('id' => $work_location_id)
							, 'company__id'
						);

					$data[] = array('holiday__id' => $header['ID'], 'company__id' => $get_company_id[0]['company__id'], 'work_location__id' => $work_location_id);
				}

				$this->HRIS_M_live_data->combo_data_set
					(
						'db_default'
						, array
							(
								'NAME' => $this->tbl_attr['TABLE_HOLIDAY_COMPANY_WORK_LOCATION']['NAME']
								, 'WHERE' => array('holiday__id' => $header['ID'])
							)
						, $data
					);
			}


			$return_value = json_encode($return_value);
			echo $return_value;
		}
	}


	/**
	 * @function ajx_update()
	 * @description update the data
	 */
	public function ajx_update()
	{
		if ($this->input->is_ajax_request() && $this->access_rights['EDIT'])
		{
			/**
			 * @description load the models
			 */
			$this->load->model(array('admin/M_live_data', 'admin/hris/HRIS_M_live_data'));


			$return_value = $this->M_live_data->update
				(
					'db_default'
					, $this->tbl_attr['TABLE']['NAME']
					, array('id' => $this->input->post('txtinput[0]'))
					, $this->input->post('txtinput')
				);



			/**
			 * @description process the company & work location detail
			 */
			$header['ID'] = $this->input->post('txtinput[0]');


			/**
			 * @description process the company
			 */
			$data = array();
			foreach ($this->input->post('txtinput[4]') as $company_id)
			{
				$data[] = array('holiday__id' => $header['ID'], 'company__id' => $company_id);
			}

			$this->HRIS_M_live_data->combo_data_set
				(
					'db_default'
					, array
						(
							'NAME' => $this->tbl_attr['TABLE_HOLIDAY_COMPANY']['NAME']
							, 'WHERE' => array('holiday__id' => $header['ID'])
						)
					, $data
				);


			/**
			 * @description process the work location
			 */
			$data = array();
			foreach ($this->input->post('txtinput[5]') as $work_location_id)
			{
				$get_company_id = $this->M_database->datas
					(
						'db_default'
						, 'hris_organization_company_work_location'
						, array('id' => $work_location_id)
						, 'company__id'
					);

				$data[] = array('holiday__id' => $header['ID'], 'company__id' => $get_company_id[0]['company__id'], 'work_location__id' => $work_location_id);
			}

			$this->HRIS_M_live_data->combo_data_set
				(
					'db_default'
					, array
						(
							'NAME' => $this->tbl_attr['TABLE_HOLIDAY_COMPANY_WORK_LOCATION']['NAME']
							, 'WHERE' => array('holiday__id' => $header['ID'])
						)
					, $data
				);


			$return_value = json_encode($return_value);
			echo $return_value;
		}
	}


	/**
	 * @function ajx_delete()
	 * @description delete the data
	 */
	public function ajx_delete($prm_key = '')
	{
		if ($this->input->is_ajax_request() && $this->access_rights['DELETE'])
		{
			/**
			 * @description load the models
			 */
			$this->load->model('admin/M_live_data');


			$return_value = $this->M_live_data->delete
				(
					'db_default'
					, $this->tbl_attr['TABLE']['NAME']
					, $prm_key
					, array($this->input->post('txtinput[0]'))
					, array('id')
				);


			$return_value = json_encode($return_value);
			echo $return_value;
		}
	}


	/**
	 * @function ajx_data_put()
	 * @description get the data from database and put them to the form via ajax!
	 * TODO: got to generate the work_location list based on the company__id list when edited [LOOK AT THE approval.php; that seems can be implemented here :) ]
	 */
	public function ajx_data_put($prm_key = '')
	{
		if ($this->input->is_ajax_request() && $this->access_rights['EDIT'] && trim($prm_key) != '')
		{
			/**
			 * @description load the models
			 */
			$this->load->model(array('admin/M_live_data', 'admin/hris/HRIS_M_live_data'));


			$return_value = $this->M_live_data->put
				(
					'db_default'
					, $this->tbl_attr['TABLE']['NAME']
					, array('id' => $prm_key)
					, $this->tbl_attr['FORM']['FIELDS']
				);

			$return_value = array
				(
					$return_value[0]
					, array_merge
						(
							$return_value[1]
							, $this->HRIS_M_live_data->combo_data_get
								(
									'db_default'
									, array
										(
											'NAME' => $this->tbl_attr['TABLE_HOLIDAY_COMPANY']['NAME']
											, 'WHERE' => array('holiday__id' => $prm_key)
											, 'FIELDS' => 'company__id'
										)
								)
							, $this->HRIS_M_live_data->combo_data_get
								(
									'db_default'
									, array
										(
											'NAME' => $this->tbl_attr['TABLE_HOLIDAY_COMPANY_WORK_LOCATION']['NAME']
											, 'WHERE' => array('holiday__id' => $prm_key)
											, 'FIELDS' => 'work_location__id'
										)
								)
						)
					, $return_value[2]
				);


			$return_value = json_encode($return_value);
			echo $return_value;
		}
	}



/**
 * @section AJAX Live Section
 */

	/**
	 * @function ajx_live_work_location_combo_put()
	 * @description get the data and put them in combobox
	 */
	public function ajx_live_work_location_combo_put($prm_company_id = '', $prm_object_start = '0', $prm_selected_value = '')
	{
		if ($this->input->is_ajax_request() && trim($prm_company_id) != '')
		{
			/**
			 * @description load the models
			 */
			$this->load->model('admin/hris/HRIS_M_live_data');


			$prm_company_id = str_replace('%2C', ',', $prm_company_id);
			if ($prm_company_id != 'null')
			{
				$prm_company_id = array('company__id in' => '('.$prm_company_id.')');
			}
			else
			{
				$prm_company_id = array();
			}
			$return_value = $this->HRIS_M_live_data->combo_fill('db_default', 'company_work_location', $prm_object_start, 'RECURSIVE', $prm_company_id, FALSE, $prm_selected_value, FALSE, TRUE);


			$return_value = json_encode($return_value);
			echo $return_value;
		}
	}



}

/** End of file holiday.php */
/** Location: ./biskitz_mpc/biskitz/controllers/admin/hris/configuration/attendance/holiday.php */
